package models

import "gorm.io/gorm"

// SysLog 日志结构体
type SysLog struct {
	// gorm.Model
	BaseModel
	User        string `gorm:"column:user;type:varchar(255);" json:"user"`
	Browser     string `gorm:"column:browser;type:varchar(50)" json:"browser"`
	ClassMethod string `gorm:"column:class_method;type:varchar(255);" json:"class_method"`
	HttpMethod  string `gorm:"column:http_method;type:varchar(20)" json:"http_method"`
	Params      string `gorm:"column:params;type:varchar(255);" json:"params"`
	RemoteAddr  string `gorm:"column:remote_addr;type:varchar(255)" json:"remote_addr"`
	RequestUri  string `gorm:"column:request_uri;type:varchar(255)" json:"request_uri"`
	Response    string `gorm:"column:response;type:text(10000);" json:"response"`
	StatusCode  int    `gorm:"column:status_code;type:int(11)" json:"status_code"`
	UseTime     int64  `gorm:"column:use_time;type:varchar(255);" json:"use_time"`
}

func (table *SysLog) TableName() string {
	return "sys_log"
}

// GetLogList 获取日志列表
func GetLogList(keyword string) *gorm.DB {
	// tx := DB.Model(new(SysLog)).Select("id,browser,class_method,http_method,remote_addr,status_code,use_time,created_at,country,region,province,city,isp")
	tx := DB.Model(new(SysLog)).Select("id,browser,class_method,http_method,remote_addr,status_code,use_time,created_at, user")
	if keyword != "" {
		tx.Where("title LIKE ?", "%"+keyword+"%")
	}
	return tx
}
